﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Orchard.Environment.Extensions;
using Orchard.Localization;
using Orchard.UI.Navigation;
using SchoolPointe.Menus.Services;

namespace SchoolPointe.Menus
{
    [OrchardSuppressDependency("Orchard.Core.Navigation.AdminMenu")]
    public class AdminMenu : INavigationProvider 
    {
        private readonly IMenuService _menuService;

        public AdminMenu(IMenuService menuService)
        {
            _menuService = menuService;
            T = NullLocalizer.Instance;
        }

        public string MenuName { get { return "admin"; } }
        public Localizer T { get; set; }

        public void GetNavigation(NavigationBuilder builder)
        {
            var menus = _menuService.GetMenus();
            builder.AddImageSet("navigation")
                .Add(T("Navigation"), "7",
                    menu =>
                    {
                        menu.Add(T("Create New Menu"), "0", item => item.Action("Create", "Admin", new { area = "Contents", id = "Menu" }));
                        if (menus.Count() == 1)
                            menu.Add(T("Edit Menu \"" + menus.First().Name + "\""), "1", item => item.Action("Edit", "Admin", new { area = "Contents", id = menus.First().MenuId }));
                        else if (menus.Count() > 1)
                            menu.Add(T("Manage Menus"), "1", item => item.Action("List", "Admin", new { area = "Contents", id = "Menu" }));
                    });
        }
    }
}